const argv = process.argv.slice(2);
const fs = require('fs');
const path = require('path');
//数组转object
const getSentryInfo = () => {
  let obj = {};
  argv.map((item) => {
    if (item !== '') {
      const key = item.split(':')[0];
      const http = item.split(':')[1];
      const url = item.split(':')[2];
      if (http && url) {
        obj[key] = `${http}:${url}`;
      } else if (http && http > 0) {
        obj[key] = parseInt(http);
      } else if (http) {
        obj[key] = http;
      } else {
        obj[key] = '';
      }
    }
  });
  return obj;
}
let obj = getSentryInfo();

console.log(obj)

const getContent = (obj) => {
  return `[defaults]
url=${obj['url']}
org=${obj['org']}
project=${obj['project']}

[auth]
token=${obj['token']}
`;
};

const content = getContent(obj);

fs.writeFile(path.resolve(__dirname, '.sentryclirc'), content, (err) => {
  if (err) throw err;
  console.log('文件已被保存');
});
